<?php
class BulkmailForm extends CFormModel {
	public $title;
	public $content;
	public $category;
	
	const OBJECT_AVAILABLE_USERS = 1;
	const OBJECT_SUBSCRIBERS = 2;
	
	/**
	 * Declares the validation rules.
	 * The rules state that username and password are required,
	 * and password needs to be authenticated.
	 */
	public function rules()
	{
		return array(
			// username and password are required
			array('title, content, category', 'required', 'message' => '请填写{attribute}。')
		);
	}

	public static function getObjectOptions() {
		return array(
			self::OBJECT_AVAILABLE_USERS => '所有正常用户',
			self::OBJECT_SUBSCRIBERS => '《心灵智慧》订阅用户'
		);
	}
	
	public function getUserCriteria() {
		$criteria = new CDbCriteria;
		switch($this->category) {
			case self::OBJECT_AVAILABLE_USERS:
				$criteria->condition = 'groupid != 5'; 
				break;
			case self::OBJECT_SUBSCRIBERS:
				$criteria->condition = 'subscribed = 1';
				break;
		}
		return $criteria;
	}
	
	/**
	 * Declares the attribute labels.
	 * If an attribute is not delcared here, it will use the default label
	 * generation algorithm to get its label.
	 */
	public function attributeLabels()
	{
		return array(
			'title' => '标题',
			'content' => '内容',
			'category' => '目标用户'
		);
	}
}